package com.guchenbo.example.object;

import com.guchenbo.example.Person;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by CreGu on 2016/6/9.
 */
public class TestObject {

    public static void main(String[] args) {
        Person person = new Person();
        person.setName("test");
        person.setAge(18);
        person.setBirthday(new Date());
        System.out.println(person.getName());
        TestObject demo = new TestObject();
        demo.change(person);
        System.out.println(person.getName());

        Person xiaoZhang = new Person();
        xiaoZhang.setName("小张");
        Person xiaoLi = new Person();
        xiaoLi.setName("小李");
        swap(xiaoZhang, xiaoLi);
        System.out.println("xiaoZhang:" + xiaoZhang.getName());
        System.out.println("xiaoLi:" + xiaoLi.getName());

        int num=20;
        demo.chan(num);
        System.out.println(num);

        Integer num2=30;
        demo.chan(num2);
        System.out.println(num2);

        demo.chan2(num2);
        System.out.println(num2);

        Integer num3 = 256;
        System.out.println(num3);
        demo.chan(num3);
        System.out.println(num3);
        demo.chan2(num3);
        System.out.println(num3);
    }
    public static void swap(Person person1, Person person2) {
        Person temp = person1;
        person1 = person2;
        person2 = temp;
        System.out.println("person1:" + person1.getName());
        System.out.println("person2:" + person2.getName());
    }

    public void chan(int num) {
        System.out.println(num);
        num=10;
        System.out.println(num);

    }
    public void chan2(Integer num) {
        System.out.println(num);
        num=10;
        System.out.println(num);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void change(Person person){
        person.setName("demo");
        System.out.println(person.getName());

        person = new Person();
        person.setName("demo2");
        System.out.println(person.getName());
    }
}
